<template>
	<view class="main-body">
		<div class="col-menu">
			<div class="col-menu-item" v-for="(item,index) in menuList" keys="index" @click="goUrl(item.url)">
				<div class="icon-box">
					<m-icon :icon="item.icon" :size="80" :color="item.color"></m-icon>
				</div>
				<div class="main-box">
					<div class="title">{{item.title}}</div>
					<div class="dis">{{item.dis}}</div>
				</div>
				<div class="more-box">
					<u-icon name="arrow-right" color="#ccc" size="20"></u-icon>
				</div>
			</div>
		</div>
		<!-- <u-grid :col="3">
				<u-grid-item>
					<u-icon name="photo" :size="46"></u-icon>
					<view class="grid-text">图片</view>
				</u-grid-item>
				<u-grid-item>
					<u-icon name="lock" :size="46"></u-icon>
					<view class="grid-text">锁头</view>
				</u-grid-item>
				<u-grid-item>
					<u-icon name="hourglass" :size="46"></u-icon>
					<view class="grid-text">沙漏</view>
				</u-grid-item>
				<u-grid-item>
					<u-icon name="photo" :size="46"></u-icon>
					<view class="grid-text">图片</view>
				</u-grid-item>
				<u-grid-item>
					<u-icon name="lock" :size="46"></u-icon>
					<view class="grid-text">锁头</view>
				</u-grid-item>
				<u-grid-item>
					<u-icon name="hourglass" :size="46"></u-icon>
					<view class="grid-text">沙漏</view>
				</u-grid-item>
			</u-grid> -->
		<!-- <view v-if="hasLogin" class="hello">
			<view class="title">
				您好 {{userName}}，您已成功登录。
			</view>
			<view class="ul">
				<u-button>按钮</u-button>
				<view>这是 uni-app 带登录模板的示例App首页。</view>
				<view>在 “我的” 中点击 “退出” 可以 “注销当前账户”</view>
			</view>
		</view>
		<view v-if="!hasLogin" class="hello">
			<view class="title">
				您好 游客。
			</view>
			<view class="ul">
				<view>这是 uni-app 带登录模板的示例App首页。</view>
				<view>在 “我的” 中点击 “登录” 可以 “登录您的账户”</view>
			</view>
		</view> -->
		<m-tab-bar></m-tab-bar>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import {
		univerifyLogin
	} from '@/common/univerify.js'

	export default {
		data() {
			return {
				// tabbar: []
				menuList:[
					{
						title:'隐患管理',
						dis:"隐患管理隐患管理隐患管理隐患管理隐患管理",
						icon:"yinhuan1",
						color:'#E54B54',
						url:"../hidden/hidden"
					},
					{
						title:'巡查管理',
						dis:"巡查管理巡查管理",
						icon:"xuncha",
						color:'#32C38E',
						url:"../hidden/hidden"
					},
					{
						title:'出入记录',
						dis:"出入记录出入记录出入记录",
						icon:"jilu",
						color:'#3C5BF3',
						url:"../hidden/hidden"
					}
				]
			}
		},
		computed: mapState(['forcedLogin', 'hasLogin', 'userName','tabBar']),
		onLoad() {
			console.log('onload',this.tabBar)
			// const loginType = uni.getStorageSync('login_type')
			// if (loginType === 'local') {
			// 	this.login(uni.getStorageSync('username'))
			// 	return
			// }
			// let uniIdToken = uni.getStorageSync('uni_id_token')
			// if (uniIdToken) {
			// 	this.login(uni.getStorageSync('username'))
			// 	uniCloud.callFunction({
			// 		name: 'user-center',
			// 		data: {
			// 			action: 'checkToken',
			// 		},
			// 		success: (e) => {

			// 			console.log('checkToken success', e);

			// 			if (e.result.code > 0) {
			// 				//token过期或token不合法，重新登录
			// 				if (this.forcedLogin) {
			// 					uni.reLaunch({
			// 						url: '../login/login'
			// 					});
			// 				} else {
			// 					uni.navigateTo({
			// 						url: '../login/login'
			// 					});
			// 				}
			// 			}
			// 		},
			// 		fail(e) {
			// 			uni.showModal({
			// 				content: JSON.stringify(e),
			// 				showCancel: false
			// 			})
			// 		}
			// 	})
			// } else {
			// 	this.guideToLogin()
			// }
		},
		methods: {
			...mapMutations(['login']),
			guideToLogin() {
				uni.showModal({
					title: '未登录',
					content: '您未登录，需要登录后才能继续',
					/**
					 * 如果需要强制登录，不显示取消按钮
					 */
					showCancel: !this.forcedLogin,
					success: (res) => {
						if (res.confirm) {
							univerifyLogin().catch((err) => {
								if (err === false) return;
								/**
								 * 如果需要强制登录，使用reLaunch方式
								 */
								if (this.forcedLogin) {
									uni.reLaunch({
										url: '../login/login'
									});
								} else {
									uni.navigateTo({
										url: '../login/login'
									});
								}
							})
						}
					}
				});
			},
			goUrl(url){
				uni.navigateTo({
					url:url
				});
			}
		}

	}
</script>

<style lang="scss" scoped>
@import  "./main.scss"
</style>
